package com.ics.atable.chat.controller;

import com.ics.atable.chat.common.BaseResponse;
import com.ics.atable.chat.expection.ErrorCode;
import com.ics.atable.chat.expection.ThrowUtils;
import com.ics.atable.chat.model.dto.ItemRetrievalDTO;
import com.ics.atable.chat.model.dto.MatchedItem;
import com.ics.atable.chat.service.RetrievalTestService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.ics.atable.chat.common.ResultUtils.success;

/**
 * 指标检索控制层
 *
 * @author haohongbin
 */
@Tag(name = "检索调试")
@RestController
@RequestMapping("/retrieval")
public class RetrievalTestController {

    @Resource
    private RetrievalTestService retrievalTestService;

    @Operation(summary = "指标检索")
    @PostMapping("/item")
    public BaseResponse<List<MatchedItem>> itemRetrieval(@RequestBody ItemRetrievalDTO itemRetrievalDTO) {
        ThrowUtils.throwIf(ObjectUtils.isEmpty(itemRetrievalDTO), ErrorCode.PARAMS_ERROR, "请求参数不能为空");
        ThrowUtils.throwIf(ObjectUtils.isEmpty(itemRetrievalDTO.getContent()), ErrorCode.PARAMS_ERROR, "用户输入不能为空");
        ThrowUtils.throwIf(ObjectUtils.isEmpty(itemRetrievalDTO.getWeights()), ErrorCode.PARAMS_ERROR, "权重列表不能为空");

        return success(retrievalTestService.itemRetrieval(itemRetrievalDTO));
    }

}
